package com.yanqu.road.server.cmd.activity.peakstronghold;

import com.yanqu.road.entity.activity.peakstronghold.config.PeakStrongHoldConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PeakStrongholdWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.peakstronghold.PeakStrongholdActivityMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_PEAK_STRONGHOLD_GUESS, desc = "")
public class PeakStrongHoldGuessCmd extends AbstractCommand {


    PeakStrongholdWarProto.PeakStrongholdGuessReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = PeakStrongholdWarProto.PeakStrongholdGuessReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PeakStrongHoldConfig config = PeakStrongholdActivityMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }

        player.sendUnionActivityGroupPacket(CrossProtocol.C_PEAK_STRONGHOLD_GUESS, reqMsg.toBuilder(), reqMsg.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }
        PeakStrongholdWarProto.PeakStrongholdGuessRespMsg.Builder respMsg = PeakStrongholdWarProto.PeakStrongholdGuessRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_PEAK_STRONGHOLD_GUESS, respMsg);
    }
}
